<%@page import="com.ksyzt.gwt.server.common.Util"%>
<%@page import="com.ksyzt.ksite2.server.modles.OAImage"%>
<%@page import="com.ksyzt.ksite2.server.database.dao.impl.NEWSDAOImpl"%>
<%@page import="com.ksyzt.ksite2.server.database.dao.INEWSDAO"%>
<%@page import="com.ksyzt.ksite2.shared.modle.NEWSObj"%>
<%@page import="com.ksyzt.ksite2.server.database.dao.impl.DRAFTDAOImpl"%>
<%@page import="com.ksyzt.ksite2.server.database.dao.IDRAFTDAO"%>
<%@page import="com.ksyzt.ksite2.shared.modle.DRAFTObj"%>
<%@page import="com.ksyzt.ksite2.server.modles.OAResponse"%>
<%@page import="com.google.gson.Gson"%>
<%@page import="com.ksyzt.ksite2.server.modles.OARequest"%>
<%@page import="com.ksyzt.ksite2.server.common.Application"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
    int draft_column_id = 142;
    Application app = new Application(request, response);
    String data = app.getPostData();
    System.out.println(data);
    Gson g = new Gson();
    OARequest oadata = g.fromJson(data, OARequest.class);

    if (oadata == null)
    {
		OAResponse res = new OAResponse();
		res.setResult(0);
		res.setMessage("请求数据格式错误");
		out.print(g.toJson(res));
    } else
    {

		NEWSObj n = new NEWSObj();
		INEWSDAO dao = new NEWSDAOImpl(Application.getConnection());
		n.setADDTIME(Util.getCurrentSQLTimestamp());
		n.setTITLE(oadata.title);
		n.setDISPLAY(1);
		n.setUSERID(1);
		n.setOID(draft_column_id);
		n.setAUTHOR(oadata.author);
		n.setSUMMARY(n.getTITLE());
		//先保存新闻 获取ID值
		dao.insertObject(n);

		if (oadata.content == null)
		{
		    oadata.content = "";
		}

		if (oadata.images != null)
		{
		    app.processOAImages(n.getID(), oadata.images);
		    for (OAImage img : oadata.images)
		    {
			if (img.type == 0)
			{
			    // replace
			    oadata.content = oadata.content.replaceAll(
				    img.replace, img.filename);
			}
		    }
		}
		n.setCONTENT(oadata.content);
		dao.updateObjectByPK(n);

		OAResponse res = new OAResponse();
		res.setResult(1);
		res.setMessage("接收成功");
		out.print(g.toJson(res));
    }
%>